package cn.iocoder.yudao.module.trade.statistics.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.module.trade.statistics.bo.AfterSaleSummaryRespBO;
import cn.iocoder.yudao.module.trade.statistics.dal.dataobject.TradeStatisticsDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

/**
 * 售后订单的统计 Mapper
 *
 * @author owen
 */
@Mapper
public interface AfterSaleStatisticsMapper extends CoreMapper<TradeStatisticsDO> {

    @Select("""
                    SELECT COUNT(1) AS afterSaleCount, SUM(refund_price) AS afterSaleRefundPrice
                    FROM trade_after_sale
                    WHERE refund_time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE
            """)
    AfterSaleSummaryRespBO selectSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime,
                                                            @Param("endTime") LocalDateTime endTime);

    @Select("""
            SELECT COUNT(1)
             FROM trade_after_sale
             WHERE status = #{status} AND deleted = FALSE
            """)
    Long selectCountByStatus(@Param("status") Integer status);

}
